<!DOCTYPE html>
<html>
<head>
<title>分享晒单</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, user-scalable=no, maximum-scale=1.0" />
<meta content="yes" name="apple-mobile-web-app-capable" />
<meta content="black" name="apple-mobile-web-app-status-bar-style" />
<meta content="telephone=no" name="format-detection" />
<link href="../assets/mobile/comm.css" rel="stylesheet" type="text/css" />
<link href="../assets/mobile/login.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" href="../assets/mobile/top.css">
<script src="../assets/js/mobile/jquery190.js" type="text/javascript"></script>
<link rel="stylesheet" href="../assets/agile/css/ratchet/css/ratchet.min.css">
<link rel="stylesheet" href="../assets/agile/css/flat/flat.component.css">
<link rel="stylesheet" href="../assets/agile/css/flat/iconline.css">
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/config.js"></script>
<script type="text/javascript" src="../script/local.js"></script>
<script type="text/javascript" src="../script/common.js"></script>
</head>

<body style="position:static;">
    <div class="h5-1yyg-v1" id="content">

<!--通用顶部-->

<!--通用顶部结束-->
<section class="clearfix g-member" style="margin-top:0px !important;">
		<div class="registerCon" style="background:none">
			<form method="post" id="faceform" enctype="multipart/form-data">
				<ul class="form">
        	        <li>
						商品：
						<a href="javascript:;" class="blue viewGoods">[查看]</a>
                    </li>
        	        <li style="margin-bottom:0;">
						<input name="title" type="text" placeholder="请填写您的晒单标题" value="">
                    </li>
        	        <li style="margin-bottom:0;">
						<textarea name="content" style="height:100px;resize:none;padding-top:10px;" placeholder="请填写您的晒单内容，不得少于15个汉字。"></textarea>
                    </li>
					<li style="margin-bottom:0;">
						晒单图片请拍实物照片，截图不予审核
					</li>
					<div style="float:left; width:220px;">
					<li style="position:relative;">
					<input type="file" name="Filedata" id="upload" style="position:absolute;top:0;left:0;z-index:2;opacity:0;width:65px;height:35px;"/>
					<div class="common-btn selectPic" style="position:absolute;top:0;left:0;z-index:1;">选择图片</div>
					</li>	
					<div style="width:710px; float:left;"></div>
					<li>
						
					</li>				
					
					<div class="fileWarp"><div id="fileQueue"></div><ul></ul></div>
					<li style="margin-top:20px;">
					<input id="shaitu" name="shaitu" type="hidden" value=""/>
					<input id="sd_submit" style="display:none;" name="submit" type="submit" value="确认添加"/>
					<div style="color: red; font-size: 20px; margin-top:10px;">晒图预览:</div>
					<div id="viewpic"></div>
					</li>
				</ul>
				
				<div class="clear"></div>
				<span class="common-btn submitInfo" style="margin:20px auto 0 auto;width:50%;">提交</span>
				
			</form>
		</div>
		
		<div class="block30"></div>
	</section>
</div>
<script type="text/javascript" src="../script/jquery.form.js"></script>
<script>
apiready = function(){
$(function(){
    
	var userinfo = '';
	if(!(userinfo = getUserinfo())){
		$.PageDialog.fail('请登录用户');
		return;
	}
	
	var sd_order_id = localData.get('sd_order_id');
	if(!sd_order_id){
		$.PageDialog.fail('数据不存在');
		return;
	}
	var isOrder = {isIn : false};
	
	GetJPData(config.url+'/app.php?act=singleinsert&uid='+userinfo.uid,{sd_order_id:sd_order_id},function(data){
		if(data['status'] == 1){
			var goods_id = data['shopinfo']['id'];
			viewGoods(goods_id);
			c(goods_id);
			isOrder.isIn = true;
		}else{
			$.PageDialog.fail('数据不存在');
			isOrder.isIn = false;
		}
	});
	
	function viewGoods(goods_id){
		$('.viewGoods').click(function(){
			openItem('dataserver',goods_id,function(id){
				localData.set('dataserver_goods_id',id);
			});
		});
	}
	
	//var i = 0;
	var i = {i:0};
	$('#upload').change(function(event) {
		if(!isOrder.isIn) return;
		$('#faceform').ajaxSubmit({
			type : 'post',
			url : config.url+'/app.php?act=singphotoup&uid='+userinfo.uid,
			beforeSend : function(){
			    api.showProgress({title:'正在上传',text:''});
				$('.selectPic').text('正在上传');
				$('#upload').hide();
			},
			success : function(res){
				$('#upload').val('');
			    api.hideProgress();
			    $('#upload').click();
				$('.selectPic').text('选择图片');
				$('#upload').show();
				if(res['status'] == 0){
					$.PageDialog.fail(res['msg']);
				}else if(res['status'] == 1){
					//i++;
					var ii = i.i++;
					if(ii == 1 || $('#shaitu').val() == ''){
						$('#shaitu').addClass('hidepic'+ii).val(res['data']['path']);
					}
					var html = '<div style="position:relative;margin-top:5px;width:100px;height:100px;float:left;margin-right:5px;" item="'+ii+'" id="pic'+ii+'">';
						html += '<div style="position:absolute;top:0px;left:0px;height:30px;width:100%;background:rgba(0,0,0,0.5);color:#fff;text-align:right;line-height:30px;" class="delete">删除&nbsp;&nbsp;</div>';
						html += '<input type="hidden" name="fileurl_tmp[]" value="'+res['data']['path']+'" class="fileurl_tmp" />';
						html += '<img src="'+config.upload_url+'/'+res['data']['thumb']+'" alt="" style="width:100px;height:100px;"  /></div>';
					$('#viewpic').before(html);
					lyzimg();
					bindPic();
				}
			}
		});
	});

	
	function bindPic(){
		$('.delete').bind('click',function(){
			var item = $(this).parent().attr('item');
			$('.hidepic'+item).val('').removeClass();
			$(this).parent().remove();
			//i--;
			var s = i.i--;
			i.i = s;
		});
	}
	
	function c(goods_id){
		$('.submitInfo').click(function(){
			var title = $('input[name=title]').val();
			var content = $('textarea[name=content]').val();
			if (!title) {
				$.PageDialog.fail("标题不能为空！");
				return false;
			}
			if (!title) {
				$.PageDialog.fail('内容不能为空！');
				return false;
			}
			if (content.length < 15) {
				$.PageDialog.fail('内容不得少于15个字！');
				return false;
			}
			var imgs = $('.fileurl_tmp').length;
			if ( imgs < 1) {
				$.PageDialog.fail('请至少上传1张晒单照片！');
				return false;
			}
			if ( imgs > 15) {
				$.PageDialog.fail('最多上传15张晒单照片！');
				return false;
			}
			var userinfo = getUserinfo();
			var sd_order_id = localData.get('sd_order_id');
			$('#faceform').ajaxSubmit({
				type : 'post',
				url : config.url+'/app.php?act=singleinsert&sd_order_id='+sd_order_id+'&uid='+userinfo.uid,
				data : {'submit': 'send'},
				beforeSend : function(event){
					api.showProgress({title:'正在提交',text:''});
				},
				success : function(data){
				    api.hideProgress();
					if(data['status']){
						localData.set('sd_ok_id',localData.get('sd_order_id'));
						$.PageDialog.ok('<s></s>'+data['msg']);
						localData.remove('sd_order_id');
						setTimeout(function(){
							appClose('singleinsert',api);
						},2000);
					}else{
						$.PageDialog.fail(data['msg']);
					}
				},
			});		
		});
	}
	
});
};
</script>
</body>
</html>